#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：V2 
@File    ：__init__.py.py
@IDE     ：PyCharm 
@Author  ：郭星
@Date    ：2025/9/8 20:19 
'''
from DRL1.GPTP.DQNAgent import DQNAgent
from DRL1.GPTP.JobShopEnv import JobShopEnv

# 初始化环境和智能体
env = JobShopEnv(num_jobs=5, num_machines=3)
agent = DQNAgent(state_size=env.num_machines, action_size=env.num_jobs * env.num_machines)

# 训练过程
episodes = 1000
for e in range(episodes):
    state = env.reset()
    done = False
    while not done:
        action = agent.act(state)
        job_idx = action % env.num_jobs
        machine_idx = action // env.num_jobs
        next_state, reward, done, _ = env.step((job_idx, machine_idx))
        agent.remember(state, action, reward, next_state, done)
        agent.replay()
        state = next_state

    if e % 100 == 0:
        print(f"Episode {e}, Makespan: {env.makespan}")
